﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;
using HRM.DAL.Report;

namespace HRM.UI.PmUI.EmpModule
{
    public partial class SearchEmployeePm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetProjects();
            }
        }

        private void GetProjects()
        {
            int empId = (int)Session["Id"];
            List<Project> projects = new List<Project>();
            ProjectManager manager = new ProjectManager();
            projects = manager.GetProjects(empId);
            selectEmployeeInProject.DataValueField = "Id";
            selectEmployeeInProject.DataTextField = "ProjectName";
            selectEmployeeInProject.DataSource = projects;
            selectEmployeeInProject.DataBind();
            selectEmployeeInProject.Items.Insert(0, "--Select Project--");
        }

        protected void SearchEmployee(object o, EventArgs e)
        {
            GetEmployeesInProject();
        }

        private void GetEmployeesInProject()
        {
            EmployeeManager empManager = new EmployeeManager();
            List<ViewEmployee> employees = new List<ViewEmployee>();
            Project project = new Project();
            project.Id = Convert.ToInt32(selectEmployeeInProject.Value);
            employees = empManager.SearchEmployeeByProject(project);
            searchEmpGrid.DataSource = employees;
            searchEmpGrid.DataBind();
            lblFondResult.ForeColor = Color.Green;
            lblFondResult.Text = "Total Employee Found :" + employees.Count.ToString();

        }

        protected void searchEmpGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            searchEmpGrid.PageIndex = e.NewPageIndex;
            GetEmployeesInProject();

        }

    }
}